package com.itheima.test1;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Test {
    public static void main(String[] args) {
        double[] arr = {0.1, 0.2, 2.1, 3.2, 5.56, 7.21};
        BigDecimal sum = new BigDecimal("0");
        for (int i = 0; i < arr.length; i++) {
            double d=arr[i];
            BigDecimal num = new BigDecimal("" + d);
            sum=sum.add(num);
        }
        System.out.println("它们的总值:"+sum);
        BigDecimal count = new BigDecimal("" + arr.length);
        BigDecimal avg = sum.divide(count,2, RoundingMode.DOWN);
        System.out.println("平均值："+avg);
    }
}
